package com.zls.controller;

import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.page.Result;
import com.zls.pojo.Subitem;
import com.zls.service.SubitemService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subitem")
public class SubitemController {
    @Autowired
    private SubitemService subitemService;
    @GetMapping("findAll")
    public List<Subitem> findAll(){
        List<Subitem> all = subitemService.findAll();
        return all;
    }

    /**
     * 工程阶段列表查询
     */
    @PostMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPageBean){
        PageResult page = subitemService.findPage(queryPageBean);
        return page;
    }
    /**
     * 工程阶段列表添加
     */
    @PostMapping("add")
    public Result add(@RequestBody Subitem subitem){
        int i = subitemService.addSubitem(subitem);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 查询修改工程阶段列表
     */
    @GetMapping("findBySuid")
    public Result findById(@RequestParam("suid") String  suid){
        Subitem subitem=subitemService.findBySuid(suid);
        Result result=new Result();
        if (ObjectUtils.isNotEmpty(subitem)){
            result.setData(subitem);
            result.setFlag(true);
        }else {
            result.setMessage("系统错误");
        }
        return result;
    }
    /**
     * 修改工程列表
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Subitem subitem){
        int i = subitemService.editSubitem(subitem);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 工程阶段列表删除
     */
    @GetMapping("delete")
    public Result delete(@RequestParam("suid")String suid){
        int i = subitemService.deleteSubitem(suid);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
}
